package cn.cas.mango.dto.param;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class NewsCluster {
  private Double score;
  private String id;
  private String type;
  private Object keywords;
  @JsonProperty(value = "entities")
  private Object entities;
  @JsonProperty(value = "entities_organization")
  private Object entitiesOrganization;
  @JsonProperty(value = "entities_place")
  private Object entitiesPlace;
  @JsonProperty(value = "entities_person")
  private Object entitiesPerson;
  private String date;
  private Object child;
  private String title;
  public List<String> getFilteredKeywords() {
    if (keywords instanceof Map) {
      keywords = new ArrayList<Map>(){{add((Map)keywords);}};
    } else if (keywords == null) {
      keywords = new ArrayList<>();
    }
    keywords = new ArrayList<>(((List<Map>) keywords));
    return ((List<Map>) keywords).stream().map(x->(String)x.get("name")).collect(Collectors.toList());
  }
  @JsonIgnore
  public String getKeywordsString() {
    return getFilteredKeywords().stream().reduce((x,y)->x+" " + y).orElse("");
  }
}
